using System;
namespace SynoManager.AudioStation.Data
{
    public class MusicFile
    {
        private readonly AudioStationService service;

        private string album;
        private string artist;
        private TimeSpan duration;
        private string genre;
        private int id;
        private int index;
        private bool isInvalid;
        private string path;
        private string title;

        internal MusicFile(Playlist playlist, AudioStationClient.PlaylistItem item)
        {
            this.service = playlist.service;
            album = item.album;
            artist = item.artist;
            duration = TimeSpan.Parse("00:"+item.duration);
            genre = item.genre;
            id = item.id;
            index = item.index;
            isInvalid = item.invalid;
            path = item.path;
            title = item.title;
        }

        internal MusicFile(AudioStationService service, AudioStationClient.LibraryItem item)
        {
            this.service = service;
            album = item.album;
            artist = item.artist;
            string[] durationParts = item.duration.Split(':');
            int minutes = Int32.Parse(durationParts[0]);
            int seconds = Int32.Parse(durationParts[1]);
            duration = new TimeSpan(0, minutes, seconds);
            genre = item.genre;
            id = Int32.Parse(item.id);
            index = Int32.Parse(item.index);
            isInvalid = item.invalid;
            path = item.path;
            title = item.title;
        }


        public string Album
        {
            get { return album; }
        }

        public string Artist
        {
            get { return artist; }
        }

        public TimeSpan Duration
        {
            get { return duration; }
        }

        public string Genre
        {
            get { return genre; }
        }

        public int ID
        {
            get { return id; }
        }

        public int Index
        {
            get { return index; }
        }

        public bool IsInvalid
        {
            get { return isInvalid; }
        }

        public string Path
        {
            get { return path; }
        }

        public string Title
        {
            get { return title; }
        }
    }
}